package com.mall.server.controller.sms;

import com.mall.model.domain.SmsHomeBrand;
import com.mall.model.vo.CommonPage;
import com.mall.model.vo.CommonResult;
import com.mall.server.service.sms.SmsHomeBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/home/brand")
public class SmsHomeBrandController {

    @Autowired
    private SmsHomeBrandService smsHomeBrandService;

    /**
     * 分页查询推荐品牌
     */
    @GetMapping("/list")
    public CommonResult list(@RequestParam(defaultValue = "1") Integer pageNum
            , @RequestParam(defaultValue = "10") Integer pageSize
            , SmsHomeBrand homeBrand) {

        CommonPage cp = smsHomeBrandService.list(pageNum, pageSize, homeBrand);

        return CommonResult.success(cp);
    }

    /**
     * 添加首页推荐品牌
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody List<SmsHomeBrand> homeBrandList) {

        smsHomeBrandService.create(homeBrandList);

        return CommonResult.success(null);
    }

    /**
     * 批量删除推荐品牌
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam("ids") List<Long> ids) {

        smsHomeBrandService.delete(ids);

        return CommonResult.success(null);
    }

    /**
     * 批量修改推荐品牌状态
     */
    @PostMapping("/update/recommendStatus")
    public CommonResult update(@RequestParam("ids") List<Long> ids,
                               SmsHomeBrand smsHomeBrand) {

        smsHomeBrandService.update(ids, smsHomeBrand);

        return CommonResult.success(null);
    }

    /**
     * 修改推荐品牌排序
     */
    @PostMapping("/update/sort/{id}")
    public CommonResult updateSort(@PathVariable Integer id,
                                   SmsHomeBrand smsHomeBrand) {

        smsHomeBrandService.updateSort(id, smsHomeBrand);

        return CommonResult.success(null);
    }


}
